package com.sumainfor.zuul.controller.tenant;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.sumainfor.common.util.CustomMap;
import com.sumainfor.common.util.JsonResult;
import com.sumainfor.zuul.entity.SysUserEntity;
import com.sumainfor.zuul.service.SysUserService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author Jack Chen
 * @Create 2019-02-16 14:06
 */
@RestController
@RequestMapping("/provider/tenant")
public class TenantProvider {

    @Autowired
    private SysUserService sysUserService;

    @PostMapping("/getPhoneNumberByUserId")
    public JsonResult getPhoneNumberByUserId(String userId) {
        if (StringUtils.isBlank(userId)) {
            return JsonResult.errorForEmpty();
        }
        EntityWrapper wrapper = new EntityWrapper();
        wrapper.eq("user_id", userId);
        SysUserEntity userEntity = sysUserService.selectOne(wrapper);
        if (userEntity == null) {
            return JsonResult.error("没有查询到数据");
        }

        return JsonResult.success(CustomMap.create("phone", userEntity.getMobile())
                .put("userName", userEntity.getName())
        );
    }

}
